package com.cn.xiaonuo.tcrfinance.tcrshops.controller;

import com.cn.xiaonuo.common.entity.BusinessMessage;
import com.cn.xiaonuo.common.utils.ApiJsonModel;
import com.cn.xiaonuo.tcrfinance.tcrorder.param.ReflectRecordParam;
import com.cn.xiaonuo.tcrfinance.tcrshops.entity.PvOrderDelivery;
import com.cn.xiaonuo.tcrfinance.tcrshops.entity.PvOrderRefund;
import com.cn.xiaonuo.tcrfinance.tcrshops.entity.PvOrderRequest;
import com.cn.xiaonuo.tcrfinance.tcrshops.param.*;
import com.cn.xiaonuo.tcrfinance.tcrshops.service.MerchantBackService;
import com.cn.xiaonuo.tcrfinance.tcrshops.service.PlatformService;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 平台管理
 *
 * @author Mark sunlightcs@gmail.com
 */
@RestController
public class PlatformController {


    @Autowired
    private PlatformService platformService;

    @Autowired
    private MerchantBackService merchantBackService;


    /**
     * @title 1.商家列表
     * @description 商家列表
     */
    @ApiOperation(value = "商家列表分页", notes = "商家列表分页")
    @PostMapping("/api/platform/shop/queryShopList")
    public BusinessMessage queryShopList( PvShopReqParam pvShopReqParam) {
        BusinessMessage message = platformService.queryShopList( pvShopReqParam);
        return message;
    }


    /**
     * @title 2.添加商家
     * @description 添加商家
     */
    @ApiOperation(value = "添加商家", notes = "添加商家")
    @PostMapping("/api/platform/shop/addShop")
    public BusinessMessage addShop(@RequestBody PvShopParam pvShop) {
        BusinessMessage<Object> message = new BusinessMessage<>();
        if(StringUtils.isBlank(pvShop.getPhone())){
            message.setCode("-1");
            message.setSuccess(false);
            message.setMessage("电话号码不能为空");
            return message;
        }
        message = platformService.addShop(pvShop);
        return message;
    }

    /**
     * 更新商品信息
     */
    @ApiOperation(value = "更新商品信息", notes = "更新商品信息")
    @PostMapping("/api/platform/shop/updateShop")
    public BusinessMessage updateShop(@RequestBody PvShopParam pvShop) {
        BusinessMessage message = platformService.updateShop(pvShop);
        return message;
    }


    /**
     * 物流订单

     */
    @ApiOperation(value = "物流订单", notes = "物流订单")
    @ApiJsonModel({
            @ApiModelProperty(name = "beginTime", value = "下单开始时间",example = "下单开始时间"),
            @ApiModelProperty(name = "endTime", value = "下单结束时间",example = "下单结束时间"),
            @ApiModelProperty(name = "deliveryStatus", value = "物流状态:0.全部1:未发货2.已发货3.已收货",example = "物流状态:0.全部1:未发货2.已发货3.已收货"),
            @ApiModelProperty(name = "jk_status", value = "结算状态:0：未结算 1:已结算",example = "结算状态:0：未结算 1:已结算"),
            @ApiModelProperty(name = "serialNumber", value = "订单号",example = "订单号"),
            @ApiModelProperty(name = "shopId", value = "商铺id",example = "商铺id"),

    })
    @PostMapping("/api/platform/selectOrderLogisticsByself")
    public BusinessMessage selectOrderLogistics(@RequestBody Map<String, Object> params) {
        BusinessMessage message = platformService.selectOrderLogisticsByself(params);
        return message;
    }

    /**
     * 订单状态更新
     */
    @ApiOperation(value = "订单状态更新", notes = "订单状态更新")
    @ApiJsonModel({
            @ApiModelProperty(name = "deliveryId", value = "地址id",example = "地址id"),
            @ApiModelProperty(name = "logisticsNum", value = "物流单号",example = "物流单号"),
            @ApiModelProperty(name = "logisticsType", value = "物流公司",example = "物流公司"),
    })
    @PostMapping("/api/platform/updateOrderLogisticsByselfStatus")
    public BusinessMessage updateOrderLogisticsByselfStatus(@RequestBody Map<String, Object> params) {
        BusinessMessage message = platformService.updateOrderLogisticsByselfStatus(params);
        return message;
    }

    /**
     * 查询物流公司与物流单号
     */
    @ApiOperation(value = "查询物流公司与物流单号", notes = "查询物流公司与物流单号")
    @ApiJsonModel({
            @ApiModelProperty(name = "deliveryId", value = "地址id",example = "地址id")
    })
    @PostMapping("/api/platform/selectDeliveryAdd")
    public BusinessMessage selectDeliveryAdd(@RequestBody PvShopParam pvShopParam) {
        BusinessMessage message = platformService.selectDeliveryAdd(pvShopParam);
        return message;
    }
    /**
     * 订单详情
     */
    @ApiOperation(value = "充值记录", notes = "充值记录")
    @PostMapping("/api/platform/selcetInGoldemDeatail")
    public BusinessMessage selcetInGoldemDeatail(@RequestBody PlatformParam params) {
        BusinessMessage message = platformService.selcetInGoldemDeatail(params);
        return message;
    }

    /**
     提现记录
     */
    @ApiOperation(value = "提现记录", notes = "提现记录")
    @PostMapping("/api/platform/selcetOutGoldemDeatail")
    public BusinessMessage selcetOutGoldemDeatail(@RequestBody  ReflectRecordParam reflectRecordParam) {
        BusinessMessage message = platformService.selcetOutGoldemDeatail(reflectRecordParam);
        return message;
    }

    /**
     * @description 物流发货记录(全)
     */
    @PostMapping("/api/platform/selectPlatformDeliveryDetail")
    public BusinessMessage selectPlatformDeliveryDetail(@RequestBody Map<String, Object> params) {
        BusinessMessage message = platformService.selectPlatformDeliveryDetail(params);
        return message;
    }

    /**
     * 振兴乡村充值体现-提现申请/提现记录
     */
    @ApiOperation(value = "振兴乡村充值体现-提现申请/提现记录", notes = "振兴乡村充值体现-提现申请/提现记录")
    @PostMapping("/api/platform/selectRemitDetail")
    public BusinessMessage selectRemitDetail(@RequestBody ReflectRecordParam reflectRecordParam) {
        BusinessMessage message = platformService.selectRemitDetail(reflectRecordParam);
        return message;
    }
    /**
     * @title 打款/结款操作
     * @description 结款操作
     */
    @ApiOperation(value = "打款/结款操作", notes = "打款/结款操作")
    @PostMapping("/api/platform/updateRemitStatus")
    public BusinessMessage updateRemitStatus(@RequestBody Map<String, Object> params) {
        BusinessMessage message = platformService.updateRemitStatus(params);
        return message;
    }

    /**
     * @title 15.批量结款操作
     * @description 批量结款操作
     */
    @PostMapping("/api/platform/updateBatchRemitStatus")
    public BusinessMessage updateBatchRemitStatus(@RequestBody Map<String, Object> params) {
        BusinessMessage message = platformService.updateBatchRemitStatus(params);
        return message;
    }

    /**
     * 订单结算
     */
    @ApiOperation(value = "订单结算", notes = "订单结算")
    @ApiJsonModel({
            @ApiModelProperty(name = "deliveryId", value = "地址id",example = "地址id"),
            @ApiModelProperty(name = "operatorId", value = "操作人",example = "操作人"),
    })
    @PostMapping("/api/platform/updateJKStatus")
    public BusinessMessage updateJKStatus(@RequestBody Map<String, Object> params) {
        BusinessMessage message = platformService.updateJKStatus(params);
        return message;
    }

    /**
     * 三七分润记录
     */
    @ApiOperation(value = "三七分润记录", notes = "三七分润记录")
    @PostMapping("/api/platform/selectNotoginsengDetail")
    public BusinessMessage selectNotoginsengDetail(@RequestBody TradeParam tradeParam) {
        BusinessMessage message = platformService.selectNotoginsengDetail(tradeParam);
        return message;
    }
    /**
     * 释放记录
     */
    @ApiOperation(value = "释放记录", notes = "释放记录")
    @ApiJsonModel({
            @ApiModelProperty(name = "accounts", value = "买方账号",example = "买方账号"),
            @ApiModelProperty(name = "productId", value = "商品代码",example = "商品代码"),
            @ApiModelProperty(name = "productName", value = "商品名称",example = "商品名称"),
            @ApiModelProperty(name = "beginTime", value = "开始时间",example = "开始时间"),
            @ApiModelProperty(name = "endTime", value = "结束时间",example = "结束时间"),
            @ApiModelProperty(name = "pageNo", value = "分页",example = "分页"),
            @ApiModelProperty(name = "pageSize", value = "分页大小",example = "分页大小"),
    })
    @PostMapping("/api/platform/selectReleasedDetails")
    public BusinessMessage selectReleasedDetails(@RequestBody Map<String, Object> params) {
        BusinessMessage message = platformService.selectReleasedDetails(params);
        return message;
    }

    /**
     * @title 1.商家列表
     * @description 商家列表
     */
    @ApiOperation(value = "商家列表", notes = "商家列表")
    @PostMapping("/api/platform/shop/list")
    public BusinessMessage list( PvShopReqParam pvShopReqParam) {
        BusinessMessage message = platformService.list( pvShopReqParam);
        return message;
    }
    /**
     * @title 奖励记录
     * @description 奖励记录
     */
    @ApiOperation(value = "奖励记录", notes = "奖励记录")
    @PostMapping("/api/platform/rewardPage")
    public BusinessMessage rewardPage(@RequestBody PlatformParam platformParam) {
        BusinessMessage message = platformService.rewardPage( platformParam);
        return message;
    }

    /**
     * @title 剩余记录
     * @description 剩余记录
     */
    @ApiOperation(value = "剩余记录", notes = "剩余记录")
    @PostMapping("/api/platform/surplusPage")
    public BusinessMessage surplusPage(@RequestBody PlatformParam platformParam) {
        BusinessMessage message = platformService.surplusPage( platformParam);
        return message;
    }
    /**
     * @title 奖励合计
     * @description 奖励合计
     */
    @ApiOperation(value = "奖励合计", notes = "奖励合计")
    @PostMapping("/api/platform/prizeTotalPage")
    public BusinessMessage prizeTotalPage(@RequestBody PlatformParam platformParam) {
        BusinessMessage message = platformService.prizeTotalPage( platformParam);
        return message;
    }
    /**
     * @title 赠品合计
     * @description 赠品合计
     */
    @ApiOperation(value = "赠品合计", notes = "赠品合计")
    @PostMapping("/api/platform/giftPage")
    public BusinessMessage giftPage(@RequestBody PlatformParam platformParam) {
        BusinessMessage message = platformService.giftPage( platformParam);
        return message;
    }

    /**
     * 物流订单

     */
    @ApiOperation(value = "普通订单", notes = "普通订单")
    @ApiJsonModel({

            @ApiModelProperty(name = "payBeginTime", value = "支付开始时间",example = "支付开始时间"),
            @ApiModelProperty(name = "payEndTime", value = "支付结束时间",example = "支付结束时间"),
            @ApiModelProperty(name = "deliverBeginTime", value = "发货开始时间",example = "发货开始时间"),
            @ApiModelProperty(name = "deliverEndTime", value = "发货结束时间",example = "发货结束时间"),
            @ApiModelProperty(name = "confirmBeginTime", value = "确认收货开始时间",example = "确认收货开始时间"),
            @ApiModelProperty(name = "confirmEndTime", value = "确认收货结束时间",example = "确认收货结束时间"),
            @ApiModelProperty(name = "deliveryStatus", value = "物流状态:0.全部1:未发货2.已发货3.已收货",example = "物流状态:0.全部1:未发货2.已发货3.已收货"),
            @ApiModelProperty(name = "jkStatus", value = "结算状态:0：未结算 1:已结算",example = "结算状态:0：未结算 1:已结算"),
            @ApiModelProperty(name = "serialNumber", value = "订单号",example = "订单号"),
            @ApiModelProperty(name = "shopId", value = "商铺id",example = "商铺id"),
            @ApiModelProperty(name = "pageSize", value = "条数",example = "条数"),
            @ApiModelProperty(name = "pageNo", value = "页数",example = "页数"),
            @ApiModelProperty(name = "userName", value = "收货人",example = "收货人"),
            @ApiModelProperty(name = "phone", value = "联系方式",example = "联系方式"),
            @ApiModelProperty(name = "paymentChannel", value = "支付方式:1微信,2支付宝,3.线下付款4.提货5验证20.余额支付",example = "支付方式:1微信,2支付宝,3.线下付款4.提货5验证20.余额支付"),
            @ApiModelProperty(name = "shopName", value = "所属商家",example = "所属商家"),

    })
    @PostMapping("/api/platform/selectGeneralOrderList")
    public BusinessMessage selectGeneralOrderList(@RequestBody PvOrderRequest pvOrderRequest) {
        BusinessMessage message = platformService.selectGeneralOrderList(pvOrderRequest);
        return message;
    }

    /**
     * 生成退款订单
     */
    @ApiOperation(value = "普通订单--关闭订单", notes = "普通订单--关闭订单")
    @PostMapping("/api/platform/generateRefundOrder")
    public BusinessMessage generateRefundOrder(@RequestBody PvOrderRefund pvOrderRefund){
        BusinessMessage message = platformService.generateRefundOrder(pvOrderRefund);
        return message;
    }


    @ApiOperation(value = "乡村振兴--退款订单", notes = "乡村振兴--退款订单")
    @PostMapping(value = "/api/platform/selectFinanceRefund")
    public BusinessMessage selectFinanceRefund(@RequestBody PvOrderRequest pvOrderRequest) {
        BusinessMessage message = platformService.selectFinanceRefund(pvOrderRequest);
        return message;
    }

    @ApiOperation(value = "乡村振兴--退款订单--审核", notes = "乡村振兴--退款订单--审核")
    @ApiJsonModel({
            @ApiModelProperty(name = "refundId", value = "退款订单id",example = "退款订单id"),
            @ApiModelProperty(name = "operateId", value = "审核人id",example = "审核人id"),
            @ApiModelProperty(name = "checkState", value = "1.待审核 2.待退款 3.退款成功/退款成功 4.退款未通过/已驳回 5：取消退",example = "1.待审核 2.待退款 3.退款成功/退款成功 4.退款未通过/已驳回 5：取消退"),
    })
    @PostMapping(value = "/api/platform/refundOrderReview")
    public BusinessMessage refundOrderReview(@RequestBody PvOrderRequest pvOrderRequest) {
        BusinessMessage message = platformService.refundOrderReview(pvOrderRequest);
        return message;
    }

    @ApiOperation(value = "乡村振兴--退款订单--取消退款", notes = "乡村振兴--退款订单--取消退款")
    @PostMapping(value = "/api/platform/cancelRefund")
    public BusinessMessage cancelRefund(@RequestBody PvOrderRequest pvOrderRequest) {
        BusinessMessage message = platformService.cancelRefund(pvOrderRequest);
        return message;
    }
    @ApiOperation(value = "乡村振兴--退款订单--确认退款", notes = "乡村振兴--退款订单--确认退款")
    @PostMapping(value = "/api/platform/confirmRefund")
    public BusinessMessage confirmRefund(@RequestBody PvOrderRequest pvOrderRequest) {
        BusinessMessage message = platformService.confirmRefund(pvOrderRequest);
        return message;
    }

    @ApiOperation(value = "乡村振兴--提货订单列表", notes = "乡村振兴--提货订单列表")
    @PostMapping(value = "/api/platform/pickUpOrder")
    public BusinessMessage pickUpOrder(@RequestBody PvOrderRequest pvOrderRequest) {
        BusinessMessage message = platformService.pickUpOrder(pvOrderRequest);
        return message;
    }

    @ApiOperation(value = "乡村振兴--取消提货订单", notes = "乡村振兴--取消提货订单")
    @PostMapping(value = "/api/platform/cancelPicking")
    public BusinessMessage cancelPicking(@RequestBody PvOrderRequest pvOrderRequest) {
        BusinessMessage message = platformService.cancelPicking(pvOrderRequest);
        return message;
    }
    @ApiOperation(value = "乡村振兴--取消提货订单--审核", notes = "乡村振兴--取消提货订单--审核")
    @PostMapping(value = "/api/platform/cancelPickingReview")
    public BusinessMessage cancelPickingReview(@RequestBody PvOrderDeliverysParam pvOrderDeliverysParam) throws Exception {
        BusinessMessage message = platformService.cancelPickingReview(pvOrderDeliverysParam);
        return message;
    }
    @ApiOperation(value = "提货订单--关闭订单", notes = "提货订单--关闭订单")
    @PostMapping("/api/platform/deliveryGenerateRefundOrder")
    public BusinessMessage deliveryGenerateRefundOrder(@RequestBody PvOrderDelivery pvOrderDelivery) throws Exception {
        BusinessMessage message = platformService.deliveryGenerateRefundOrder(pvOrderDelivery);
        return message;
    }

    @ApiOperation(value = "乡村振兴--商户订单退款查询(拉卡拉)", notes = "乡村振兴--商户订单退款查询(拉卡拉)")
    @PostMapping(value = "/api/common/platform/idmRefundQuery")
    public BusinessMessage idmRefundQuery(@RequestBody String outRefundOrderNo) {
        BusinessMessage message = platformService.idmRefundQuery(outRefundOrderNo);
        return message;
    }
}
